package sort;

import com.gule.gl.leetcode.editor.cn.definition.TreeNode;

/**
 * @ClassName: leetcode-study Tree2Link
 * @Description: sort
 * @Author: 逸伦
 * @Date: 2023/3/8 09:32
 * @Version: 1.0
 */
public class Tree2Link {

	public static void main(String[] args) {

	}

	public TreeNode prev = null;

	public TreeNode Convert(TreeNode pRootOfTree) {
		if(pRootOfTree == null){
			return null;

		}
		convertChild(pRootOfTree);
		TreeNode head = pRootOfTree;
		while(head.left != null){   //pRootOfTree表示二叉树头结点，应该返回链表头结点！！！
			head = head.left;
		}
		return head;
	}
	public void convertChild(TreeNode cur) {
		if (cur == null) {
			return;
		}
		convertChild(cur.left);

		cur.left = prev;

		if (prev != null) {
			prev.right = cur;
		}

		prev = cur;

		convertChild(cur.right);

	}
}
